import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;


public class Utility {
	
	private static final long DAY_TO_MILLISECOND  	= 86400000L; // 1000 * 60 * 60 * 24
	private static final long HOUR_TO_MILLISECOND 	= 3600000L; //1000 * 60 * 60
	private static final long MINUTE_TO_MILLISECOND 	= 60000L; // 1000 * 60
	private static final long SECOND_TO_MILLISECOND 	= 1000L;
	
	public static Date nextDays(Date origin, int days) {
		long time = origin.getTime() + ( DAY_TO_MILLISECOND * days );
		return new Date(time);
	}
	
	public static Date[] splitDateByBasedMonth(Date date) {
		Date[] retDates = new Date[2];
		
		Calendar cal = GregorianCalendar.getInstance();
		cal.setTime(date);		
		int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		cal.set(Calendar.DAY_OF_MONTH, lastDay);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		retDates[0] = new Date( cal.getTimeInMillis() );
		
		Date temp = Utility.nextDays(retDates[0], 1);
		cal.setTime(temp);
		int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
		cal.set(Calendar.DAY_OF_MONTH, firstDay);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		retDates[1] = new Date( cal.getTimeInMillis() );
		
		//System.out.println(retDates[0]);
		//System.out.println(retDates[1]);
		return retDates;
	}
	

	
	public static boolean isSameYearMonth(Date one, Date other) {
		Calendar cal = GregorianCalendar.getInstance();
		cal.setTime(one);
		int oneYear = cal.get(GregorianCalendar.YEAR);
		int oneMonth = cal.get(GregorianCalendar.MONTH);
		
		cal.setTime(other);
		int otherYear = cal.get(GregorianCalendar.YEAR);
		int otherMonth = cal.get(GregorianCalendar.MONTH);
		
		if( oneYear == otherYear && oneMonth == otherMonth ) {
			return true;
		} else {
			return false;
		}
	}
	
	public static void main(String[] args) {
		//Date date = new Date(System.currentTimeMillis());
		//Date date2 = new Date(date.getTime() + DAY_TO_MILLISECOND * 50);
		
		Calendar cal = GregorianCalendar.getInstance();
		cal.set(2013, 11, 22);
		Date date3 = cal.getTime();
		//System.out.println("date  = " + date);
		//System.out.println("date2 = " + date2);
		//System.out.println(Utility.isSameYearMonth(date, date2));
		//splitDateForSameYearMonth(date3);
	}
}
